﻿using System;
using Zx.Accessor;

namespace Zx
{
    /// <summary>
    /// 获取或设置实例的属性
    /// 借助委托
    /// </summary>
    public static class ObjVisit
    {
        private static DynamicPropertyAccessorCache s_cache =
            new DynamicPropertyAccessorCache();

        public static object Get(this object o, string propertyName)
        {
            return s_cache.GetAccessor(o.GetType(), propertyName).GetValue(o);
        }

        public static void Set(this object o, string propertyName, object val)
        {
            s_cache.GetAccessor(o.GetType(), propertyName).SetValue(o, val);
        }

        public static Type GetPropertyType(this object o, string propertyName)
        {
            return s_cache.GetAccessor(o.GetType(), propertyName).GetPropertyType();
        }


    }
}
